//
//  Calculator.m
//  NSClassFormStringDemo
//  计算器类
//  Created by mobao on 16/3/30.
//  Copyright © 2016年 mobao. All rights reserved.
//

#import "Calculator.h"

@implementation Calculator

+(float)calculate:(float)number1 number2:(float)number2 operators:(NSString*)operators{
    //使用OC反射获得一个与字符串同名的类
    Class class = NSClassFromString(operators);
    float result;
    if (class) {
        //实例化这个类，并传入计算器的两个操作数
        Operation *operation = [[class alloc]initWithNumber1:number1 Number2:number2];
        //调用运算方法，并返回结果
        result = [operation operate];
        return result;
    }
    return 0;
}

@end
